/**
 * Created by Administrator on 2016/9/8.
 */
var myText = document.getElementsByClassName("myText");
var myBtn = document.getElementsByClassName("myBtn");
var mySpan = document.getElementsByClassName("mySpan");
function myCheck(){
    var values = myText[0].value;
    var count = 0;
    for(var i = 0;i<values.length;i++){
        if(/[a-zA-Z0-9]/.test(values[i])){
            count += 1;
        }else if(/[\u4E00-\u9FA5]/.test(values[i])){
            count += 2;
        }
    }
    if(count == 0){
        myText[0].style.borderColor = 'red';
//        myText[0].setAttribute('borderColor','red');
        mySpan[0].innerText = '请输入字符';
//        mySpan[0].setAttribute('color','red');
        mySpan[0].style.color = 'red';
    }
   else if(count >= 4 && count <= 16){
        myText[0].style.borderColor = 'green';
        mySpan[0].innerText = '格式正确';
        mySpan[0].setAttribute('color','green');
        mySpan[0].style.color = 'green';
    }else{
        myText[0].style.borderColor = 'red';
        myText[0].setAttribute('borderColor','red');
        mySpan[0].innerText = '字符长度为4~16！';
        mySpan[0].setAttribute('color','red');
        mySpan[0].style.color = 'red';
    }
}

myBtn[0].onclick = myCheck;